<?php
session_start();
require_once('models/Auth.class.php');	
require_once("configs/db_connect.php");

if (!Auth::isCheckSuccess())
{
	 header('Location: index.php');
}
else
{
	 require_once('models/MyAccount.class.php');
	 require_once('configs/common.php');
	 
	 $user_id=$_GET['id'];
	 	 
	 try 
	{		
	 
		 if (!is_numeric($user_id))
		 {
			 $template = $twig->loadTemplate('user_not_found.html');
			 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
			 echo $template->render($data);
			 return;
		 }
		 else
		 {
			 $user_id=(int)$user_id;
		 }
	 	 
		 if (!is_int($user_id))
		 {
			 $template = $twig->loadTemplate('user_not_found.html');
			 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
			 echo $template->render($data);
		 }
		 else
		 {
			 $userModel=new MyAccount($user_id);
			 
			 if (!$userModel->user_data['exist'])
			 {
				 $template = $twig->loadTemplate('user_not_found.html');
				 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
				 echo $template->render($data);
				 return;
			 }
			 $template = $twig->loadTemplate('user_profile.html');			 
			 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
			 $data['user']=$userModel->getUserData();	
			 
			 echo $template->render($data);
		 }
  
	} 
	catch (Exception $e) 
	{
		 die ('ERROR: ' . $e->getMessage());
	}
}

?>